package cc.bailongma.me.fragment;


import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import com.amap.api.location.c;

import cc.bailongma.me.R;
import cc.bailongma.me.adapter.CalendarAdapter;
import cc.bailongma.me.adapter.LocationListAdapter;
import cc.bailongma.me.entity.Location;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class PositionListFragment extends Fragment implements OnClickListener{

	private ListView lv;
	private GridView gv;
	private LocationListAdapter locationAdapter;
	private CalendarAdapter calendarAdapter;
	private List<Location> locations;
	private RelativeLayout layout_container;
	private String[] date=new String[35];
	private boolean isShow;
	
 	public PositionListFragment() {
		getData();
	}
	private void getData() {
		locations=new ArrayList<Location>();
		for(int i=0;i<20;i++){
			Location location=new Location("2015.05.05", "14:"+i, "国内领先的数字地图、导航和位置服务解决方案提供商国内领先的数字地图、导航和位置服务解决方案提供商", "定位类型：LBS 上传状态：主动上传");
			locations.add(location);
		}
		Calendar calendar=Calendar.getInstance();
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		int first=calendar.get(Calendar.DAY_OF_WEEK)-1;
		int maxDay=calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
		int month = calendar.get(Calendar.MONTH);
		calendar.set(Calendar.MONTH, month-1);
		int lastMaxDay=calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
		for(int i=0;i<date.length;i++){
 			if(i<first){
 				date[i]=lastMaxDay-first+1+i+"";
 			}else if(i==first){
 				date[i]=1+"";
 			}else if(i<maxDay+first){
 				date[i]=i-first+1+"";
 			}else if(i==first+maxDay){
 				date[i]=maxDay+"";
 			}
 			else{
 				date[i]=i-(maxDay+first)+"";
 			}
 		}
	}
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view= inflater.inflate(R.layout.positionfragment,container,false);
		lv=(ListView) view.findViewById(R.id.listView1);
		gv=(GridView) view.findViewById(R.id.gridview);
		view.findViewById(R.id.tv_title).setOnClickListener(this);
		layout_container=(RelativeLayout) view.findViewById(R.id.layout_container);
		locationAdapter=new LocationListAdapter(getActivity(),locations);
		calendarAdapter=new CalendarAdapter(getActivity(), date);
		lv.setAdapter(locationAdapter);
		gv.setAdapter(calendarAdapter);
		return view;
	}
	
		
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.tv_title:
			showOrHide();
			break;

		default:
			break;
		}
		
	}
	
	private void showOrHide(){
		if(isShow){
			layout_container.setVisibility(View.INVISIBLE);
			isShow=false;
		}else{
			layout_container.setVisibility(View.VISIBLE);
			isShow=true;
		}
	}
	
}
